<?php

namespace Sharks\Core\Support\Log;

use Monolog\Handler\StreamHandler;
use Monolog\Logger;
use Sharks\Core\AppContext;
use Sharks\Core\Cfg\AppConfig;

class MonologFileLogger extends LogFactory {

    private $monolog;

    public function __construct() {
        $logPath = AppContext::instance()->path()->app->storage . AppConfig::get("logging.path", "/log");
        $level = AppConfig::get('logging.level', 'warning');
        $this->monolog = new Logger("Logging");
        $this->monolog->pushHandler(
            new StreamHandler($logPath . "/Logging" . '_' .date("Ymd") . '.log', $level));
    }

    function debug($msg) {
        if ($this->isDebug()) {
            $this->monolog->addDebug($msg);
        }
    }

    function info($msg) {
        if ($this->isInfo()) {
            $this->monolog->addInfo($msg);
        }
    }

    function warning($msg) {
        if ($this->isWarning()) {
            $this->monolog->addWarning($msg);
        }
    }

    function error($msg) {
        if ($this->isError()) {
            $this->monolog->addError($msg);
        }
    }

    function critical($msg) {
        if ($this->isCritical()) {
            $this->monolog->addCritical($msg);
        }
    }

    function alter($msg) {
        if ($this->isAlter()) {
            $this->monolog->addAlert($msg);
        }
    }
}